/*
 * Filename:    CostCoverHospiatalLevelHelp.java
 * Copyright:   2014 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2014年10月16日
 */
package com.paic.mhis.hcpms.quota.settlement.biz.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.dto.KpiGradeDTO;
import com.paic.mhis.hcpms.quota.settlement.biz.service.CostConstansts;
import com.paic.mhis.hcpms.quota.settlement.dto.CostCoverDTO;
import com.paic.mhis.hcpms.quota.settlement.dto.CostDataDTO;

/**
 * 根据医院级别来查询的帮助类
 * 
 * @author DUQIFANG262
 * 
 */
@Component("costCoverHospiatalLevelHelp")
public class CostCoverHospiatalLevelHelp {
	/**
	 * 根据医院级别维度返回的值转换对应的费用分布的DTO
	 * 
	 * @param list
	 * @return
	 */
	public CostDataDTO getCostDataDTOFromHospitalLevel(List<KpiGradeDTO> list, String endDate,
			Map<String, Integer> orderMap) {

		CostDataDTO bean = this.getCostDataVOFromListKpiGradeDTO(list, endDate, orderMap);

		return bean;

	}

	private CostDataDTO getCostDataVOFromListKpiGradeDTO(List<KpiGradeDTO> kpiGradeDTOList, String endDate,
			Map<String, Integer> orderMap) {

		// List<CostCoverDTO> listMedical = new ArrayList<CostCoverDTO>(); //
		// 保存药费占比的全年六个月纪录
		// List<CostCoverDTO> listOpertion = new ArrayList<CostCoverDTO>(); //
		// 保存手术费占比的全年六个月纪录
		// List<CostCoverDTO> listCheck = new ArrayList<CostCoverDTO>(); //
		// 保存检验费占比的全年六个月纪录

		List<HashMap<Integer, CostCoverDTO>> listMedical = new ArrayList<HashMap<Integer, CostCoverDTO>>();

		List<HashMap<Integer, CostCoverDTO>> listOpertion = new ArrayList<HashMap<Integer, CostCoverDTO>>();

		List<HashMap<Integer, CostCoverDTO>> listCheck = new ArrayList<HashMap<Integer, CostCoverDTO>>();

		if (kpiGradeDTOList != null && kpiGradeDTOList.size() > 0) {

			for (KpiGradeDTO bean : kpiGradeDTOList) {
				String kpiCode = bean.getKpiCode();
				BigDecimal kpiValue = bean.getKpiValue();
				String kpiTime = bean.getKpiTime();
				if (kpiValue == null) {
					kpiValue = new BigDecimal(0);
				}

				if (CostConstansts.medicalIndciationCode.equals(kpiCode)) { // 药费占比

					CostCoverDTO vo = new CostCoverDTO();
					vo.setMedicalPer(kpiValue);
					vo.setDate(kpiTime);

					HashMap<Integer, CostCoverDTO> map = new HashMap<Integer, CostCoverDTO>();
					map.put(orderMap.get(kpiTime), vo);
					listMedical.add(map);
				}

				if (CostConstansts.opertionIndicationCode.equals(kpiCode)) { // 手术费占比

					CostCoverDTO vo = new CostCoverDTO();
					vo.setOperationPer(kpiValue);
					vo.setDate(kpiTime);

					HashMap<Integer, CostCoverDTO> map = new HashMap<Integer, CostCoverDTO>();
					map.put(orderMap.get(kpiTime), vo);
					listOpertion.add(map);
				}

				if (CostConstansts.checkIndicationCode.equals(kpiCode)) { // 检验费占比

					CostCoverDTO vo = new CostCoverDTO();
					vo.setCheckPer(kpiValue);
					vo.setDate(kpiTime);

					HashMap<Integer, CostCoverDTO> map = new HashMap<Integer, CostCoverDTO>();
					map.put(orderMap.get(kpiTime), vo);
					listCheck.add(map);
				}
			}
		} else {
			return null;
		}

		CostDataDTO costDataVoBean = CostConstansts.getCostDataDTO(listMedical, listOpertion, listCheck, endDate,
				orderMap);
		return costDataVoBean;

	}

}
